package com.xmkj.bearuser.home.user;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.common.cons.Constans;
import com.common.retrofit.bean.HomeBean;
import com.common.utils.EmptyUtils;
import com.common.utils.SPUtils;
import com.common.widget.recyclerview.refresh.adapter.CommonAdapter;
import com.common.widget.recyclerview.refresh.adapter.ViewHolder;
import com.xmkj.bearuser.R;
import com.xmkj.bearuser.count.LoginActivtiy;
import com.xmkj.bearuser.pk.GoodsDetailsActivity;

import java.util.List;

/**
 * Create by leo
 * 创建日期：2018/6/29
 * 描述：
 */

public class HomeNewAdapter extends CommonAdapter<HomeBean.NewListEntity> {
    public HomeNewAdapter(Context context, List<HomeBean.NewListEntity> data) {
        super(context, data);
    }

    @Override
    protected void convert(ViewHolder holder, final HomeBean.NewListEntity item, int position) {
        holder.setImageStrOvalBugle(R.id.iv_img, item.pic_url);
        holder.setText(R.id.tv_price, item.price);
        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(EmptyUtils.isEmpty(SPUtils.getShareString(Constans.HASHID))){
                    Intent intent = new Intent(mContext, LoginActivtiy.class);
                    mContext.startActivity(intent);
                }else {
                    Intent intent = new Intent(mContext, GoodsDetailsActivity.class);
                    intent.putExtra(GoodsDetailsActivity.ID,item.id+"");
                    intent.putExtra(GoodsDetailsActivity.TYPE,"1");
                    mContext.startActivity(intent);
                }


            }
        });
    }

    @Override
    protected int getItemViewLayoutId(int position, HomeBean.NewListEntity item) {
        return R.layout.item_home;
    }
}
